import { SET_USER_INFO } from "./actionTypes.js"
let defaultState = {
	avatar:"",
	role:"",
	token:"",
	userNme:""
}
 // 取值  判断storage   userItem
let userItem = localStorage.getItem("userItem")?JSON.parse(localStorage.getItem("userItem")):{};
defaultState = userItem;



const reducer = (state=defaultState,action)=>{
	let newState = JSON.parse(JSON.stringify(state))
	switch(action.type){
		case SET_USER_INFO:
			newState.avatar = action.userInfo.avatar
			newState.role = action.userInfo.role
			newState.token = action.userInfo.token
			newState.userName = action.userInfo.userName
		break;
		default:break;
	}
	console.log(newState);
	localStorage.setItem("userItem",JSON.stringify(newState))
	return newState;
}

export default reducer